package com.opennews.openplatform.myspringbootcore.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class DateRangeValidator implements ConstraintValidator<ValidDateRange, DateRangeValidatable> {
    @Override
    public boolean isValid(DateRangeValidatable value, ConstraintValidatorContext context) {
        if (value.getStartDate() == null || value.getEndDate() == null) {
            return true;
        }

        return value.getEndDate().isAfter(value.getStartDate());
    }
}
